home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / pgm_ctrl / vbswit / vbswitch.bas < prev    next >
Encoding:
BASIC Source File  |  1994-10-11  |  6.2 KB  |  156 lines

  1. Option Explicit
  2.  
  3. ' Copyright ⌐ 1994 by Computer Technologies, Inc. All rights reserved.
  4.  
  5. Global Const KEY_TAB = &H9
  6. Global Const KEY_ALT = &H12
  7.  
  8. Global Const SC_TASKLIST = &HF130
  9.  
  10. Global Const WM_COMMAND = &H111
  11. Global Const WM_SYSCOMMAND = &H112
  12. Global Const WM_SYSKEYDOWN = &H104
  13. Global Const WM_SYSKEYUP = &H105
  14. Global Const WM_LBUTTONDBLCLK = &H203
  15.  
  16. Global Const MF_BYCOMMAND = &H0
  17. Global Const MF_APPEND = &H100
  18. Global Const MF_SEPARATOR = &H800
  19. Global Const MF_ENABLED = &H0
  20. Global Const MF_STRING = &H0
  21.  
  22. Global Const MB_ICONINFORMATION = 64
  23.  
  24. Global Const IDM_ABOUT = 108
  25.  
  26. Global gnDesktopHwnd        As Integer
  27.  
  28. Declare Function APIGetDesktopHwnd Lib "User" Alias "GetDesktopHwnd" () As Integer
  29. Declare Function APIGetDesktopWindow Lib "User" Alias "GetDesktopWindow" () As Integer
  30. Declare Function APIGetSystemMenu Lib "User" Alias "GetSystemMenu" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
  31. Declare Function APIDeleteMenu Lib "User" Alias "DeleteMenu" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  32. Declare Function APIAppendMenu Lib "User" Alias "AppendMenu" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  33. Declare Function APIShowWindow Lib "User" Alias "ShowWindow" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  34. Declare Function APIFindWindow Lib "User" Alias "FindWindow" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
  35. Declare Function APIArrangeIconicWindows Lib "User" Alias "ArrangeIconicWindows" (ByVal hWnd As Integer) As Integer
  36. Declare Function APIGetPrivateProfileString Lib "Kernel" Alias "GetPrivateProfileString" (ByVal lpAppName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  37.  
  38. Sub APP_About ()
  39.  
  40. ' Copyright ⌐ 1994 by Computer Technologies, Inc. All rights reserved.
  41.     
  42.     Dim tTempStr            As String
  43.     Dim tCRLF               As String
  44.         
  45.     tCRLF = Chr$(13) & Chr$(10)
  46.     tTempStr = "Copyright ⌐ 1994 by Computer Technologies, Inc." & tCRLF & "All rights reserved."
  47.     tTempStr = tTempStr & tCRLF & tCRLF & "Version 1.0 - Released October 11, 1994."
  48.     tTempStr = tTempStr & tCRLF & tCRLF & "This demo program and all associated code is the property of Computer Technologies, Inc. It is provided as a service for the personal use of the members of the MS-BASIC forum on CompuServe, and other interested Visual Basic developers."
  49.     tTempStr = tTempStr & tCRLF & tCRLF & "Author:" & Chr$(9) & "Eric Brierley"
  50.     tTempStr = tTempStr & tCRLF & "CIS:" & Chr$(9) & "71163,2657"
  51.     tTempStr = tTempStr & tCRLF & "Phone:" & Chr$(9) & "1-704-634-1766"
  52.     MsgBox tTempStr, MB_ICONINFORMATION, "About VB-Switch"
  53.  
  54. End Sub
  55.  
  56. Function APP_IniRead (tSectionName As String, tItemName As String, tItemType As String, tFileName As String) As Variant
  57.  
  58. ' Copyright ⌐ 1993, 1994 by Computer Technologies, Inc. All rights reserved.
  59.  
  60.     Dim tReturnStr          As String * 256
  61.     Dim lReturnSize         As Long
  62.     Dim nBufferSize         As Integer
  63.     Dim tTempStr            As String
  64.  
  65.     nBufferSize = 255
  66.  
  67.     lReturnSize = APIGetPrivateProfileString(tSectionName, tItemName, "", tReturnStr, nBufferSize, tFileName)
  68.     tTempStr = Trim$(Left$(tReturnStr, lReturnSize))
  69.  
  70.     Select Case Left$(UCase$(tItemType), 2)
  71.     Case "ST"            ' String
  72.     APP_IniRead = tTempStr
  73.     Case "IN"            ' Integer
  74.     If tTempStr <> "" Then APP_IniRead = CVar(tTempStr) Else APP_IniRead = 0
  75.     Case "BO"            ' Boolean (True/False)
  76.     If Left$(UCase$(tTempStr), 1) = "T" Then
  77.         APP_IniRead = True
  78.       Else
  79.         APP_IniRead = False
  80.     End If
  81.     Case "TI"            ' Time
  82.     Case "LO"            ' Long
  83.     APP_IniRead = CVar(tTempStr)
  84.     Case "SI"            ' Single
  85.     APP_IniRead = CVar(tTempStr)
  86.     Case "CU"            ' Currency
  87.     APP_IniRead = CVar(tTempStr)
  88.     Case "DO"            ' Double
  89.     APP_IniRead = CVar(tTempStr)
  90.     End Select
  91.  
  92. End Function
  93.  
  94. Sub Main ()
  95.  
  96. ' Copyright ⌐ 1994 by Computer Technologies, Inc. All rights reserved.
  97.  
  98.     Dim hMenu               As Integer
  99.     Dim nHandle             As Integer
  100.     Dim nResult             As Integer
  101.     Dim tCommand            As String
  102.     Dim bHide               As Integer
  103.     Dim tCaption            As String
  104.  
  105.     Const SW_HIDE = 0
  106.     Const SW_SHOW = 5
  107.     Const GWL_STYLE = (-16)
  108.  
  109. ' Get the handle of the desktop window so we can trap for
  110. ' double clicks used to bring up the task manager.
  111.     gnDesktopHwnd = APIGetDesktopHwnd()
  112.  
  113.     Load frmNoSwitch
  114.     frmNoSwitch.WindowState = 1                      ' Minimized
  115.  
  116. ' Check the INI file for the 'Hide' option. Then check the command
  117. ' line for a /HIDE switch. The INI file overrides the command line
  118. ' if 'Hide' is set to 'True'.
  119.     bHide = False
  120.     nResult = APP_IniRead("Options", "Hide", "Boolean", App.Path & "\VBSWITCH.INI")
  121.     If nResult = True Then
  122.     bHide = True
  123.       Else
  124.     tCommand = UCase$(Trim$(Command$))          ' Get the command line
  125.     If InStr(1, tCommand, "/HI") <> 0 Then bHide = True
  126.     End If
  127.     
  128.     If bHide = True Then
  129.     nHandle = APIFindWindow(0&, (frmNoSwitch.Caption))
  130.     nResult = APIShowWindow(nHandle, SW_HIDE)
  131.     nResult = APIArrangeIconicWindows((APIGetDesktopWindow()))
  132.     Exit Sub
  133.     End If
  134.  
  135. ' We are not hidden, so show the about box and configure the application
  136.     Call APP_About
  137.     tCaption = APP_IniRead("Captions", "Form", "String", App.Path & "\VBSWITCH.INI")
  138.     frmNoSwitch.Caption = tCaption
  139.  
  140. ' Now we get a copy of the system menu, delete the "switch to"
  141. ' item, and remove the seperator bars.
  142.     hMenu = APIGetSystemMenu((frmNoSwitch.hWnd), False)
  143.     nResult = APIDeleteMenu(hMenu, SC_TASKLIST, MF_BYCOMMAND)
  144.     nResult = APIDeleteMenu(hMenu, 0, MF_BYCOMMAND)
  145.     nResult = APIDeleteMenu(hMenu, 0, MF_BYCOMMAND)
  146.  
  147. ' Add our own 'About...' item to the menu
  148.     tCaption = APP_IniRead("Captions", "About", "String", App.Path & "\VBSWITCH.INI")
  149.     nResult = APIAppendMenu(hMenu, MF_SEPARATOR, 0, "")
  150.     nResult = APIAppendMenu(hMenu, MF_ENABLED Or MF_STRING, IDM_ABOUT, tCaption)
  151.  
  152.     frmNoSwitch.Show             ' Let the user know we are here
  153.  
  154. End Sub
  155.  
  156.